package com.ww.springboot.boot.thread.study;

import java.util.concurrent.TimeUnit;

/**
 *
 * 未开线程，只有一个任务循环执行
 *
 * @author wanwei
 */
public class TryConcurrency {
    public static void main(String[] args) {
        browseNews();
        enjoyMusic();
    }

    /*** Browse the latest news.*/
    private static void browseNews() {
        for (; ; ) {
            System.out.println("Uh-huh, the good news.");
            sleep(1);
        }
    }

    /*** Listening and enjoy the music.*/
    private static void enjoyMusic() {
        for (; ; ) {
            System.out.println("Uh-huh, the nice music.");
            sleep(1);
        }
    }

    /*** Simulate the wait and ignore exception.* @param seconds*/
    public static void sleep(int seconds) {
        try {
            TimeUnit.SECONDS.sleep(seconds);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}